## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
View(IM_total)
View(IM_maincountries)
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
View(IM_maincountries_adjusted)
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
View(IM_total_adjusted)
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
## Run the codes in the following order
source("code/01-processing.R")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
## Export datasets
#trade deficit
trade_deficit <- EX_total_adjusted %>%
select(month, EX_2024 = cumsum_2024, EX_2025 = real_cumsum_2025) %>%
left_join(IM_total_adjusted %>%
select(month, IM_2024 = cumsum_2024, IM_2025 = real_cumsum_2025),
by = "month") %>%
#trade balance (Exports - Imports)
mutate(
deficit_2024 = EX_2024 - IM_2024,
deficit_2025 = EX_2025 - IM_2025
) %>%
filter(month == "July")%>%
select(month, IM_2024, IM_2025, EX_2024, EX_2025, deficit_2024, deficit_2025)
## Select data to export
#imports
IM_country_adjusted <- IM_maincountries_adjusted%>%
select("cumsum_2024", "real_cumsum_2025", "ytd_compare") %>%
rename(
"Imports (CIF) in 2024" = cumsum_2024,
"Real Imports (CIF) in 2025" = real_cumsum_2025,
"Year-to-date comparison" = ytd_compare
)
#exports
ex_country_adjusted <- EX_maincountries_adjusted %>%
select("cumsum_2024", "real_cumsum_2025", "ytd_compare") %>%
rename(
"Exports (FAS) in 2024" = cumsum_2024,
"Real Exports (FAS) in 2025" = real_cumsum_2025,
"Year-to-date comparison" = ytd_compare
)
#export data
wb <- createWorkbook()
# 1
addWorksheet(wb, "Merchandise trade-Total")
writeData(wb, "Merchandise trade-Total", trade_deficit)
# 2
addWorksheet(wb, "Imports-main countries")
writeData(wb, "Imports-main countries", IM_maincountries_adjusted)
# 3
addWorksheet(wb, "Exports-main countries")
writeData(wb, "Exports-main countries", EX_maincountries_adjusted)
#save to Excel file
output_file <- file.path(path_to_output, "output.xlsx")
saveWorkbook(wb, output_file, overwrite = TRUE)
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "raw data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("raw data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("raw data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
data_path <- "raw data"
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "data"
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
## Data inputs
data_path <- "For QC/data"
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "For QC/data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "C:\Users\Ye.Zhang\OneDrive - Peter G. Peterson Institute for International Economics\trade tracker\For QC\data"
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "C:\\Users\\Ye.Zhang\\OneDrive - Peter G. Peterson Institute for International Economics\\trade tracker\\For QC\\data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("raw data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "C:\\Users\\Ye.Zhang\\OneDrive - Peter G. Peterson Institute for International Economics\\trade tracker\\For QC\\data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("ad/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "C:\\Users\\Ye.Zhang\\OneDrive - Peter G. Peterson Institute for International Economics\\trade tracker\\For QC\\data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "C:\\Users\\Ye.Zhang\\OneDrive - Peter G. Peterson Institute for International Economics\\trade tracker\\For QC\\data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
## Packages
library(tidyverse)
library(readxl)
library(openxlsx)
library(here)
library(ggplot2)
library(countrycode)
library(lubridate)
library(scales)
library(dplyr)
## Data inputs
data_path <- "C:\\Users\\Ye.Zhang\\OneDrive - Peter G. Peterson Institute for International Economics\\trade tracker\\For QC\\data"
#trade data
path_to_IM <- file.path(data_path, "trade data/all_countries_imports.xlsx")
path_to_EX <-file.path(data_path, "trade data/all_countries_exports.xlsx")
#import/export price index - total
IR <- read_excel(file.path(data_path, "price index/IR.xlsx"), sheet = "Monthly")
IQ <- read_excel(file.path(data_path, "price index/IQ.xlsx"), sheet = "Monthly")
#import/export price index - detailed
im_index <- read.delim("data/price index/ei.data.07.LocalityofOrigin", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ex_index <- read.delim("data/price index/ei.data.08.LocalityofDestination", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
ei_series <- read.delim("data/price index/ei.series", header = TRUE, sep = "\t", stringsAsFactors = FALSE)
## Path to save outputs
path_to_output <- here("output")
## Run the codes in the following order
source("code/01-processing.R")
source("code/02-constructing datasets.R")
source("code/03-price adjustment.R")
source("code/04-export data.R")
